<template>
<view class="tab-content">
	<!-- <view class="form_list">
		<view class="label">调拨类型</view>
		<view class="input">
			<uni-data-select
			      v-model="type"
			      :localdata="range"
			      @change="change"
				  type="line"
			    ></uni-data-select>
		</view>
	</view> -->
	<view class="form_list" v-show="type==2?true:false">
		<view class="label">开始编码</view>
		<view class="input">
			<uni-easyinput v-model="invNumStart" :placeholderStyle="placeholderStyle" placeholder="请输入开始物料编码" trim="all"></uni-easyinput>
		</view>
	</view>
	<view class="form_list" v-show="type==2?true:false">
		<view class="label">结束编码</view>
		<view class="input">
			<uni-easyinput v-model="invNumEnd" :placeholderStyle="placeholderStyle" placeholder="请输入结束物料编码" trim="all"></uni-easyinput>
		</view>
	</view>
	<tableHead prestr="DB" :order_type="16" ref="thead" :sel_source="false" :isallot="true"></tableHead>
	
	<view class="swiper-button">
		<button @click="$refs.thead.toListFh()" class="del_btn">复核列表</button>
		<button  @click="toList" class="ok_btn">调拨列表</button>
		<button @click="toAdd">添加</button>
	</view>
</view>
</template>
<script>
import tableHead from "@/component/table-head.vue"
import {
  uniDataSelect,
  uniEasyinput,
  uniDatetimePicker
} from "@dcloudio/uni-ui"

export default {
	components: {
	  uniDataSelect,uniEasyinput,uniDatetimePicker,tableHead
	},
  data() {
    return {
	  placeholderStyle:'font-size:17px;',
	  
	  invNumStart:'',
	  invNumEnd:'',
	  
	  type: 1,//调拨类型
	  range: [
		  { value: 1, text: "默认" },
		  //{ value: 2, text: "物料编码段" },
	  ],
	  user:uni.getStorageSync('user'),
    }
  },
  onLoad(option){
  	  this.$Func.setBarTitle('新增调拨')
  	  //初始化
  	  setTimeout(()=>{
  	  	this.$refs.thead.init()
  	  },500)
  },
  methods: {
    change(e){
		if(e==1){
			this.invNumStart = ''
			this.invNumEnd = ''
		}
	},
	toList(){
		uni.navigateTo({
			url:'/pages/allot/list'
		})
	},
	async toAdd(){
		if(this.type==2){
			if(this.invNumStart == ''&&this.invNumEnd == ''){
				this.$Api.msg('开始或结束编码不能都为空')
				return 
			}
		}
		
		let bill = {
			'FBillNo':this.$refs.thead.FBillNo,
			'FDate':this.$refs.thead.FDateVal,
			'type':this.type,
			'stock_id':this.$refs.thead.stock_id,
			'to_stock_id':this.$refs.thead.to_stock_id,
			'to_shelves_id':this.$refs.thead.to_shelves_id,
			'to_shelves_name':this.$refs.thead.to_shelves_name,
			'invStart':this.invNumStart,
			'invEnd':this.invNumEnd,
			'rowStart':0,//暂时用这个来当，目标库区id
			'rowEnd':0,
			'totalnum':0,
			'status':0,//默认未完成
			'syn_status':0,
			'userid':this.user.userid,
			'create_date':this.$Func.getDateTime('today'),
			'remark':this.$refs.thead.remark
		}
		
		//插入数据
		uni.showLoading();
		await this.$Db.addSaveData('allot',bill)
		.then(res=>{
			this.$Api.msg('添加成功','success')
			this.reset()
			setTimeout(()=>{
				this.toList()
			},800)
		})
		.catch(error=>{
			this.$Api.msg('添加失败','error') 
		});
		uni.hideLoading()
	},
	reset(){
		this.$refs.thead.init()
		this.type = 1
		this.invNumStart = ''
		this.invNumEnd = ''
	}
  },
  mounted(e) {}
}
</script>
<style lang="scss">
</style>